"""
# -*- coding: utf-8 -*-

Created on 2021/5/25 10:48

@File: ping_database.py
@Author: LT
@Description: Use of this module
"""
import pymysql
from ..common.read_settings import SettingsWrapper


class PingDatabase(SettingsWrapper):
    def __init__(self):
        SettingsWrapper.__init__(self)
        self.ping_result = None
        self.ping_nominated_database()

    def ping_nominated_database(self):
        """这个实例一建立就要进行ping通处理"""
        try:
            db = pymysql.connect(**self.database_connect_kwargs)
        except:
            # 说明连接不超过，db为None
            self.ping_result = False
        else:
            # 说明连接成功，可以关闭连接了
            self.ping_result = True
            db.close()


if __name__ == '__main__':
    exp = PingDatabase()
    if exp.ping_result:
        print('succeed')
    else:
        print('failed')
